<?php

namespace App\Http\Controllers\Admin;

use App\Common\Responses;
use App\Http\Controllers\Controller;
use App\Utils\Logic\lak\Register;
use App\Utils\Service\Ly\JwtServer;
use App\Utils\Service\SMSSelection;
use Illuminate\Http\Request;
use App\Models\Ly\wxLogin;
class IndexController extends Controller
{
    /*
     * 发送短信
     * @lak
     * */
    public function SMS(Request $request){
        try {
            $type = $request->post('type');
            $phone = $request->post('phone');
            $res = SMSSelection::Selection($type)->makeReservation($phone);
            $res =  json_decode(json_encode($res),true);
            return Responses::success($res,200,'发送成功');
        }catch (\Exception $exception){
            return Responses::error([],2001,'失败');
        }
    }

    /*
     * 注册
     * @name lak
     * */
    public function UseRegister(Request $request){
        try {
            (int)$phone = $request->post('phone');
            (int)$code = $request->post('code');
            $request->validate([
                'phone' => 'required|max:11',
                'code' => 'required',
            ]);

            $res = Register::register($phone,$code);

            return Responses::success($res,200,'发送成功');
        }catch (\Exception $exception){
            return Responses::error([],2001,'已注册');
        }
    }


    /*
     * 微信登录
     * lak
     * */
    public function WxEmpowerLogin(Request $request){
        try {
            $code = $request->get('code');
            $nickName = $request->get('nickName');
            $avatarUrl = $request->get('avatarUrl');
            $data = \App\Utils\Service\lak\WxLogin::WxUserInfoLogin($code,$nickName,$avatarUrl);
            return Responses::success($data,200,'登录成功');
        }catch (\Exception $exception){
            return Responses::error([],2001,'登录失败');
        }
    }





}
